﻿@model SystemMenuUpdateViewModel


@{
    ViewBag.Title = "编辑后台信息";
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Update</title>
</head>
<body>

    <div class="row">
        <div class="col-md-10 col-md-offset-1">
            <div class="panel panel-headline">
                <div class="panel-heading">
                    <h2 class="panel-title">编辑后台菜单</h2>
                </div>

                <div class="panel-body">
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-md-8">
                                <form method="post">
                                    <div class="form-group">
                                        <label for="Title">链接名称:</label>
                                            <input asp-for="Title" class="form-control" />
                                        <span asp-validation-for="Title"></span>
                                    </div>

                                    <div class="form-group">
                                        <label for="Link">链接:</label>
                                        <input asp-for="Link" class="form-control" />
                                        <span asp-validation-for="Link" class="text-danger"></span>
                                    </div>

                                    <div class="form-group">
                                        <label for="Icon">图标:</label>
                                        <input asp-for="Icon" class="form-control" />
                                        <span asp-validation-for="Icon" class="text-danger"></span>
                                    </div>

                                    <div class="form-group">
                                        <label for="ParentList">菜单等级:</label>
                                        <select id="FirstMenu" name="ParentList" class="form-control">
                                            @if (Model.ParentList[0] == 1)
                                            {
                                                <option value="1" selected>一级菜单</option>
                                                <option value="2">二级菜单</option>
                                                <option value="3">三级菜单</option>
                                            }
                                            else if (Model.ParentList[0] == 2)
                                            {
                                                <option value="1">一级菜单</option>
                                                <option value="2" selected>二级菜单</option>
                                                <option value="3">三级菜单</option>
                                            }
                                            else if (Model.ParentList[0] == 3)
                                            {
                                                <option value="1">一级菜单</option>
                                                <option value="2">二级菜单</option>
                                                <option value="3" selected>三级菜单</option>
                                            }

                                        </select>
                                        <br/>
                                        <select id="secondMenu" class="form-control" name="ParentList" style="display:none;"></select><br/>
                                        <select id="thirdMenu" class="form-control" name="ParentList" style="display:none;"></select>

                                    </div>

                                    <div class="form-group">
                                        <button class="btn btn-primary">提交</button>
                                    </div>

                                </form>
                            </div>
                        </div>
                    </div>
                </div>

            </div>
        </div>
    </div>

    @section Scripts
    {
        
        <script>
            
        $(function()
        {
            var FirstMenu = $("#FirstMenu").val();
            console.log(FirstMenu);
            if(FirstMenu == 2)
            {
                $("#secondMenu").show();
                $("#thirdMenu").hide();

                $.get("../../../ForumManage/SystemMenu/GetSysMenuList",function(data)
                {
                    
                    var str = "";
                    for(let i = 0; i < data.length; i++)
                    {
                        if(data[i].id == @Model.ParentList[1])
                        {
                            str += "<option value='"+data[i].id+"' selected>"+data[i].title+"</option>";
                        }
                        else
                        {
                            str += "<option value='"+data[i].id+"'>"+data[i].title+"</option>";
                        }
                    }
                    $("#secondMenu").html(str);
                },"json");
            }
            if(FirstMenu == 3)
            {
                $("#secondMenu").show();
                $("#thirdMenu").show();

                $.get("../../../ForumManage/SystemMenu/GetSysMenuList",function(data)
                {
                    var str = "";
                    for(let i = 0; i < data.length; i++)
                    {
                        if(data[i].id == @Model.ParentList[1])
                        {
                            str += "<option value='"+data[i].id+"' selected>"+data[i].title+"</option>";
                        }
                        else
                        {
                            str += "<option value='"+data[i].id+"'>"+data[i].title+"</option>";
                        }
                    }
                    $("#secondMenu").html(str);

                    $.get("../../../ForumManage/SystemMenu/GetSysMenuList",{parentId:$("#secondMenu").val()},function(data)
                    {
                        var sstr = "";
                        for(let j = 0; j < data.length; j++)
                        {
                            if(data[j].id == @Model.ParentList[2])
                            {
                                str += "<option value='"+data[j].id+"' selected>"+data[j].title+"</option>";
                            }
                            else
                            {
                                str += "<option value='"+data[j].id+"'>"+data[j].title+"</option>";
                            }    
                        }
                        $("#thirdMenu").html(sstr);
                    },"json");

                },"json");
            }
            else
            {
                $("#secondMenu").hide();
                $("#thirdMenu").hide();
            }
        });

        $("#FirstMenu").change(function(){
          let msg =  $(this).val();
          console.log(msg);
          if(msg == 2)
          {
            $("#secondMenu").show();
            $("#thirdMenu").hide();
                $.get("../../ForumManage/SystemMenu/GetSysMenuList",function(data){
                 //用户得到所有的一级菜单值,并且把这个值存放到secondMenu下拉列表当中
                   // console.log(data);
                 //我们需要把data当中的内容绑定到对应的下拉列表当中
                 var str ="";
                 for(let i = 0 ; i < data.length;i++)
                 {
                    str +="<option value='"+data[i].id+"'>"+data[i].title+"</option>";
                 }

                 $("#secondMenu").html(str);

                },"json");
          }
          else if(msg == 3){
             $("#secondMenu").show();
             $("#thirdMenu").show();
              $.get("../../ForumManage/SystemMenu/GetSysMenuList",function(data){
                 //用户得到所有的一级菜单值,并且把这个值存放到secondMenu下拉列表当中

                 //我们需要把data当中的内容绑定到对应的下拉列表当中
                 let str ="";
                 for(let i = 0 ; i < data.length;i++)
                 {
                    str +="<option value='"+data[i].id+"'>"+data[i].title+"</option>";
                 }

                 $("#secondMenu").html(str);

                 $.get("../../ForumManage/SystemMenu/GetSysMenuList",{parentId:$("#secondMenu").val()},function(data){
                    let ddstr = "";
                     for(let i = 0 ; i < data.length;i++)
                     {
                        ddstr +="<option value='"+data[i].id+"'>"+data[i].title+"</option>";
                     }
                     $("#thirdMenu").html(ddstr);


                },"json")

                },"json");
          }
          else if(msg == 1){
            $("#secondMenu").hide();
            $("#thirdMenu").hide();
          }
        //    if($(this).val() == "2")
        //    {
        //        $("#secondMenu").show();
        //        $("#thirdMenu").hide();

        //        $.get("../../Manage/SystemMenu/GetMenuList",function(data){
        //         //用户得到所有的一级菜单值,并且把这个值存放到secondMenu下拉列表当中
        //           // console.log(data);
        //         //我们需要把data当中的内容绑定到对应的下拉列表当中
        //         var str ="";
        //         for(let i = 0 ; i < data.length;i++)
        //         {
        //            str +="<option value='"+data[i].id+"'>"+data[i].title+"</option>";
        //         }

        //         $("#secondMenu").html(str);

        //        },"json");

        //    }
        //    else if($(this).val() == "3"){
        //        $("#secondMenu").show();
        //        $("#thirdMenu").show();
        //        $.get("../../Manage/SystemMenu/GetMenuList",function(data){
        //         //用户得到所有的一级菜单值,并且把这个值存放到secondMenu下拉列表当中

        //         //我们需要把data当中的内容绑定到对应的下拉列表当中
        //         let str ="";
        //         for(let i = 0 ; i < data.length;i++)
        //         {
        //            str +="<option value='"+data[i].id+"'>"+data[i].title+"</option>";
        //         }

        //         $("#secondMenu").html(str);

        //         $.get("../../Manage/SystemMenu/GetMenuList",{parentId:$("#secondMenu").val()},function(data){
        //            let ddstr = "";
        //             for(let i = 0 ; i < data.length;i++)
        //             {
        //                ddstr +="<option value='"+data[i].id+"'>"+data[i].title+"</option>";
        //             }
        //             $("#thirdMenu").html(ddstr);


        //        },"json")

        //        },"json");




        //    }
        //    else
        //    {
        //        $("#secondMenu").hide();
        //        $("#thirdMenu").hide();
        //    }
        //});
    });

        </script>

    }

</body>
</html>


